package com.leyou.page.mq;

import com.leyou.common.constants.MQConstants;
import com.leyou.page.service.PageService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * User: ycs
 * Date: 2020/8/27
 * Time: 19:08
 *
 * @author: ycs
 * Description: No Description
 * 静态页面更新监听器
 */

@Component
public class ItemListen {
    @Autowired
    private PageService pageService;
    /**
     * 上架监听
     * @param spuId 参数要与消息提供者提供的消息类型一致
     */
    //监听注解参数 1.消息对列 2. 交换机 3.路由key
    @RabbitListener(bindings = @QueueBinding(
            //绑定对列 参数1.对列名称2.是否持久化
            value = @Queue(value = MQConstants.Queue.PAGE_ITEM_UP,durable = "true"),
           // 绑定交换机 参数 1. 交换机名称 2. 交换机类型
            exchange = @Exchange(value = MQConstants.Exchange.ITEM_EXCHANGE_NAME,type = ExchangeTypes.TOPIC),
            //路由key
            key = MQConstants.RoutingKey.ITEM_UP_KEY
    ))
    public void addItem(Long spuId){

        pageService.CreateStaticPage(spuId);
    }
    /**
     * 下架监听
     **/

    //监听注解参数 1.消息对列 2. 交换机 3.路由key
    @RabbitListener(bindings = @QueueBinding(
            //绑定对列 参数1.对列名称2.是否持久化
            value = @Queue(value = MQConstants.Queue.PAGE_ITEM_DOWN,durable = "true"),
            //绑定交换机 参数 1. 交换机名称 2. 交换机类型
            exchange = @Exchange(value = MQConstants.Exchange.ITEM_EXCHANGE_NAME,type = ExchangeTypes.TOPIC),
            //路由key
            key = MQConstants.RoutingKey.ITEM_DOWN_KEY
    ))
    public void delItem(Long spuId){
       pageService.delItem(spuId);
    }

}
